home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / JLookAndFeelComboBox.java < prev    next >
Text File  |  1998-09-15  |  2KB  |  90 lines

  1. package com.symantec.itools.swing;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.util.Vector;
  6. import com.sun.java.swing.*;
  7. import com.sun.java.swing.event.*;
  8.  
  9. public class JLookAndFeelComboBox
  10.     extends JComboBox
  11.     implements ActionListener, Runnable
  12. {
  13.     public JLookAndFeelComboBox()
  14.     {
  15.         super();
  16.         
  17.         setupInitialValues();
  18.         refelectCurrentUI();
  19.         
  20.         addActionListener(this);
  21.     }
  22.     
  23.     protected void setupInitialValues()
  24.     {
  25.         UIManager.LookAndFeelInfo[] lnfInfos = UIManager.getInstalledLookAndFeels();
  26.         for (int i = 0;i < lnfInfos.length;i++)
  27.             addItem(lnfInfos[i].getName());
  28.     }
  29.     
  30.     protected void refelectCurrentUI()
  31.     {
  32.         String currLnFName = UIManager.getLookAndFeel().getName();
  33.         
  34.         UIManager.LookAndFeelInfo[] lnfInfos = UIManager.getInstalledLookAndFeels();
  35.         for (int i = 0;i < lnfInfos.length;i++)
  36.         {
  37.             if (lnfInfos[i].getName().equals(currLnFName))
  38.             {
  39.                 setSelectedIndex(i);
  40.                 break;
  41.             }
  42.         }
  43.     }
  44.     
  45.     public void actionPerformed(ActionEvent actionEvent)
  46.     {
  47.         if (java.beans.Beans.isDesignTime())
  48.             return;
  49.         
  50.         int selectedLnF = getSelectedIndex();
  51.         
  52.         UIManager.LookAndFeelInfo[] lnfInfos = UIManager.getInstalledLookAndFeels();
  53.         
  54.         try
  55.         {
  56.             UIManager.setLookAndFeel(lnfInfos[selectedLnF].getClassName());
  57.         }
  58.         catch(Exception e)
  59.         {
  60.             e.printStackTrace();
  61.             refelectCurrentUI();
  62.         }
  63.         
  64.         SwingUtilities.invokeLater(this);
  65.     }
  66.     
  67.     public void run()
  68.     {
  69.         //Find top root pane
  70.         JRootPane topRoot = SwingUtilities.getRootPane(this);
  71.         if (topRoot != null)
  72.         {
  73.             while (true)
  74.             {
  75.                 Container rootParent = topRoot.getParent();
  76.                 if (rootParent == null)
  77.                     break;
  78.                 
  79.                 JRootPane possibleRoot = SwingUtilities.getRootPane(rootParent);
  80.                 if (possibleRoot == null || possibleRoot == topRoot)
  81.                     break;
  82.                 
  83.                 topRoot = possibleRoot;
  84.             }
  85.             
  86.             SwingUtilities.updateComponentTreeUI(topRoot);
  87.         }
  88.     }
  89. }
  90.